.TH std::basic_streambuf::pubsetbuf,std::basic_streambuf::setbuf 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::basic_streambuf::pubsetbuf,std::basic_streambuf::setbuf \- std::basic_streambuf::pubsetbuf,std::basic_streambuf::setbuf

.SH Synopsis
   public:                                                                         \fB(1)\fP
   basic_streambuf<CharT, Traits>* pubsetbuf( char_type* s, std::streamsize n )
   protected:
   virtual basic_streambuf<CharT, Traits>* setbuf( char_type* s, std::streamsize n \fB(2)\fP
   )

   1) Calls setbuf(s, n) of the most derived class.
   2) The base class version of this function has no effect. The derived classes may
   override this function to allow removal or replacement of the controlled character
   sequence (the buffer) with a user-provided array, or for any other
   implementation-specific purpose.

.SH Parameters

   s - pointer to the first CharT in the user-provided buffer
   n - the number of CharT elements in the user-provided buffer

.SH Return value

   1) The return value of setbuf(s, n).
   2) this

.SH Example

   Provides a 10k buffer for reading. On linux, the strace utility may be used to
   observe the actual number of bytes read.


// Run this code

 #include <fstream>
 #include <iostream>
 #include <string>

 int main()
 {
     int cnt = 0;
     std::ifstream file;
     char buf[1024 * 10 + 1];

     file.rdbuf()->pubsetbuf(buf, sizeof buf);

     file.open("/usr/share/dict/words");

     for (std::string line; getline(file, line);)
         ++cnt;

     std::cout << cnt << '\\n';
 }

.SH Possible output:

 356010

   Defect reports

   The following behavior-changing defect reports were applied retroactively to
   previously published C++ standards.

     DR    Applied to             Behavior as published               Correct behavior
                      the default behavior of setbuf was only        specified as no-op
   LWG 158 C++98      specified                                      for all cases
                      if gptr() is not null and not equal to egptr()

.SH See also

   setbuf    attempts to replace the controlled character sequence with an array
   \fB[virtual]\fP \fI\fI(virtual protected member function\fP of\fP
             std::basic_stringbuf<CharT,Traits,Allocator>)
   setbuf    provides user-supplied buffer or turns this filebuf unbuffered
   \fB[virtual]\fP \fI(virtual protected member function of std::basic_filebuf<CharT,Traits>)\fP

   setbuf    attempts to replace the controlled character sequence with an array
   \fB[virtual]\fP \fI(virtual protected member function of std::strstreambuf)\fP
   setbuf    sets the buffer for a file stream
             \fI(function)\fP
